#!/usr/bin/env python

'''
    After you are happy with the assignments, this program can be used to
    convert the assignments.txt to a file that can be uploaded into the SIS.
'''

import os, sys

def loadUnmap(style):
    ''' Load up the map that was created by txt2map.py '''
    lines = open('unmap-%s.txt' % style, 'r').readlines()
    map = {}
    for l in lines:
        args = l.split()
        map[args[1]] = args[0]
    return map

def main():
    print 'Creating SIS upload file from assignments.txt'
    try:
        fp = open('run/assignments.txt', 'r')
    except:
        print 'ERROR: You need to copy assignments.txt to this directory'
        sys.exit(1)
    ofp = open('sis-upload.txt', 'w')
    rmap = loadUnmap('reviewers')
    smap = loadUnmap('submissions')
    for l in fp.readlines():
        if l[0] == '#':
            continue
        args = l.split()
        sub = args[0]
        rev = args[1]
        ofp.write('%s %s\n' % (smap[sub], rmap[rev]))
    print "That was fast, wasn't it?\n"
    print 'Now, send sis-upload.txt to the owner of the SIS'

if __name__ == "__main__":
    main()
